﻿using System.Windows;
using System.Windows.Input;

namespace Twi.COMMON.WPF
{
    /// <summary>
    /// CommonPopup.xaml 的交互逻辑
    /// </summary>
    public partial class CommonPopup : Window
    {
        //public string _content { get; set; }
        private bool _isAllowBlank = true;
        private string _blankText = "";
        public CommonPopup(string title, string content)
        {
            InitializeComponent();
            this.Title = title;
            //this._content = content;
            this.TxtContent.Text = content;
            this.TxtContent.Focus();
        }

        public CommonPopup(string title, string content, bool isAllowBlank,string blankText)
        {
            InitializeComponent();
            this.Title = title;
            //this._content = content;
            this.TxtContent.Text = content;
            this._isAllowBlank = isAllowBlank;
            this._blankText = blankText;
            this.TxtContent.Focus();
        }

        private void TxtContent_PreviewKeyUp(object sender, KeyEventArgs e)
        {
            //if (e.Key == Key.Enter)
            //{
            //    BtnSave_Click(null, null);
            //}
        }

        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            if (_isAllowBlank && this.TxtContent.Text.Trim() == "")
            {
                Twi.COMMON.WPF.Tools.GMessageInfo(_blankText);
                this.TxtContent.Focus();
                return;
            }
            //this._content = this.TxtContent.Text;
            this.DialogResult = true;
        }

        private void BtnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
